import { proxy } from 'valtio'
import { post } from '../request'
export const state = proxy({
    current_page: { label: '工作台' },
    brands: [],
    partitions: [],
    shop: [],
    platform: [
        { label: '全部店铺', value: '' },
        { label: '美团', value: '美团' },
        { label: '饿了么', value: '饿了么' },
        { label: '百度', value: '百度' }
    ],
    menus: [],
    options1: [
        { label: '今日', value: '1' },
        { label: '近7日', value: '7' },
        { label: '近30日', value: '30' }
    ],
    getBrand: () => {
        post('/brand/getBrand').then((res: any) => {
            state.brands = res.brandNameList
        })
    },
    getPartition: () => {
        post('/area/getArea').then((res: any) => {
            state.partitions = res.areaNameList
        })
    },
    getShop: () => {
        post('/shop/getShop').then((res: any) => {
            state.shop = res.shopCate
        })
    },
    worker_data: {},
    setCurrentPage: (current_page: any) => {
        state.current_page = current_page
    },
    init: async () => {
        const user = JSON.parse(localStorage.getItem('user') || '{}')
        if (!user) return false
        const menu = await post('system/getMenu', { user })
        if (menu) {
            state.menus = menu
        }
    }
})
